package handlers

import (
	"github.com/gin-gonic/gin"
	"gorm.io/gorm"
	"repo-master/models"
)

func RepoAdd(c *gin.Context) {
	repo_type := c.PostForm("repo_type")
	repo_name := c.PostForm("repo_name")
	repo_address := c.PostForm("repo_address")
	if repo_type == "" || repo_name == "" || repo_address == "" {
		c.JSON(200, gin.H{
			"code": 500,
			"msg":  "字段不能为空",
		})
		return
	}
	data := models.Repo{
		Model:       gorm.Model{},
		RepoType:    repo_type,
		RepoName:    repo_name,
		RepoAddress: repo_address,
	}
	err := models.DB.Create(&data).Error
	if err != nil {
		c.JSON(200, gin.H{
			"code": 500,
			"msg":  "添加失败",
		})
		return
	}
	c.JSON(200, gin.H{
		"code": 200,
		"msg":  "添加成功",
	})
	return
}
